package com.huacai.restbooking.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huacai.common.annotation.Log;
import com.huacai.common.core.controller.BaseController;
import com.huacai.common.core.domain.AjaxResult;
import com.huacai.common.enums.BusinessType;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.huacai.restbooking.domain.RestaurantBooking;
import com.huacai.restbooking.service.IRestaurantBookingService;
import com.huacai.common.utils.poi.ExcelUtil;
import com.huacai.common.core.page.TableDataInfo;

/**
 * 餐厅预订Controller（更新）
 *
 * @author huacai
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/huacai/booking")
public class RestaurantBookingController extends BaseController
{
    @Autowired
    private IRestaurantBookingService restaurantBookingService;

    /**
     * 查询餐厅预订列表
     */
    @PreAuthorize("@ss.hasPermi('huacai:booking:list')")
    @GetMapping("/list")
    public TableDataInfo list(RestaurantBooking restaurantBooking)
    {
        startPage();
        List<RestaurantBooking> list = restaurantBookingService.selectRestaurantBookingList(restaurantBooking);
        return getDataTable(list);
    }

    /**
     * 导出餐厅预订列表
     */
    @PreAuthorize("@ss.hasPermi('huacai:booking:export')")
    @Log(title = "餐厅预订", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RestaurantBooking restaurantBooking)
    {
        List<RestaurantBooking> list = restaurantBookingService.selectRestaurantBookingList(restaurantBooking);
        ExcelUtil<RestaurantBooking> util = new ExcelUtil<RestaurantBooking>(RestaurantBooking.class);
        util.exportExcel(response, list, "餐厅预订数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<RestaurantBooking> util = new ExcelUtil<RestaurantBooking>(RestaurantBooking.class);
        util.importTemplateExcel(response, "餐厅预订数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "餐厅预订", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('huacai:booking:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<RestaurantBooking> util = new ExcelUtil<RestaurantBooking>(RestaurantBooking.class);
        InputStream inputStream = file.getInputStream();
        List<RestaurantBooking> list = util.importExcel(inputStream );
        inputStream.close();
        int count = restaurantBookingService.batchInsertRestaurantBooking(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取餐厅预订详细信息
     */
    @PreAuthorize("@ss.hasPermi('huacai:booking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(restaurantBookingService.selectRestaurantBookingById(id));
    }

    /**
     * 新增餐厅预订
     */
    @PreAuthorize("@ss.hasPermi('huacai:booking:add')")
    @Log(title = "餐厅预订", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RestaurantBooking restaurantBooking)
    {
        return toAjax(restaurantBookingService.insertRestaurantBooking(restaurantBooking));
    }

    /**
     * 修改餐厅预订
     */
    @PreAuthorize("@ss.hasPermi('huacai:booking:edit')")
    @Log(title = "餐厅预订", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RestaurantBooking restaurantBooking)
    {
        return toAjax(restaurantBookingService.updateRestaurantBooking(restaurantBooking));
    }

    /**
     * 删除餐厅预订
     */
    @PreAuthorize("@ss.hasPermi('huacai:booking:remove')")
    @Log(title = "餐厅预订", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(restaurantBookingService.deleteRestaurantBookingByIds(ids));
    }
}
